
#ifndef	MEMORY_STATISTICS_H
#define	MEMORY_STATISTICS_H


#include "common.h"


namespace	memory
{
	struct	heap_statistics_t
	{
		volatile long	alloc;
		volatile long	free;
	};

	struct	lookaside_statistics_t
	{
		volatile long	alloc;
		volatile long	free;
	};

	struct	cache_statistics_t
	{
		size_t					count;
		lookaside_statistics_t*	lookaside;
	};


	class	statistics
	{
	public:

		statistics();
		~statistics();

		bool	create( bool enable, size_t heap_count, size_t cache_count, size_t lookaside_count );
		void	destroy();

		void	clear();

		void	inc_heap_alloc( size_t idx );
		void	inc_heap_free( size_t idx );

		void	inc_cache_alloc( size_t cache_idx, size_t las_idx );
		void	inc_cache_free( size_t cache_idx, size_t las_idx );


		size_t	get_heap_count()	const;
		size_t	get_cache_count()	const;

		const heap_statistics_t*	get_heap( size_t idx )	const;
		const cache_statistics_t*	get_cache( size_t cache_idx )	const;

	private:

		heap_statistics_t*		get_heap( size_t idx );
		lookaside_statistics_t*	get_lookaside( size_t cache_idx, size_t las_idx );

	private:

		heap_statistics_t*	heaps_;
		size_t				heap_count_;

		cache_statistics_t*	caches_;
		size_t				cache_count_;

	};
}



#endif